package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.*;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @AutoFill(OperationType.UPDATE)
    void putMeal(Setmeal setmeal);

    Page<SetmealVO> getMeals(Long categoryId, String name, Integer status);

    void deleteMeals(List<Long> ids);

    @AutoFill(OperationType.INSERT)
    void addMeal(Setmeal setmeal);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getMealByid(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateCategory(Category category);

    Page<Category> getCategorys(String name, Integer type);

    // 在CategoryMapper.java接口中使用注解（替换原有的方法声明）
    @AutoFill(OperationType.INSERT)
    @Insert("INSERT INTO category (type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "VALUES (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void addCategory(Category category);

    @Select("select * from category where type = #{type}")
    List<Category> getCategoryByType(Integer type);

    @Select("select * from dish where category_id = #{id}")
    List<DishVO> getDishByCategoryId(Long id);


    @Delete("delete from category where id = #{id}")
    void deleteCategory(Long id);

    List<DishVO> pageDish(Long categoryId, String name, Integer status);

    @Select("select * from dish where id = #{id}")
    DishVO getDishById(Long id);

    @Select("select status from dish where id = #{id}")
    Integer getDishsById(Long id);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> getFlavorsByDishId(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    @AutoFill(OperationType.INSERT)
    Long addDish(Dish dish);

    void deleteDish(List<Long> ids);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getDishBycategoryId(Long categoryId);

    void addDishFlavor(List<DishFlavor> dishFlavor);

    @Select("select setmeal_id from setmeal_dish where dish_id = #{id}")
    List<Long> getDishSetMealId(Long id);

    void deleteflavor(List<Long> ids);

    @Select("select id from dish where name = #{name}")
    Long getDishIdByName(String name);

    @Insert("INSERT INTO setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) " +
            "VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Long addSetmeal(Setmeal setmeal);


    void addSetmealDish(List<SetmealDish> setmealDishes);

    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteSetmealDish(Long id);

    @Select("select dish_id from setmeal_dish where setmeal_id = #{id}")
    List<Long> getDishIdBySetMealId(long id);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getDishBySetMealId(long id);

    @Select("select status from setmeal where id =#{setmealId}")
    Integer getSetmealStatusBySermealId(Long setmealId);

    @Select("select * from setmeal where name = #{name}")
    Setmeal getSetmealBySetmealName(String name);

    List<Category> getTypeListByStatus(Integer type);

    @Select("select * from setmeal where category_id = #{category}")
    List<SetmealVO> getsetmealByCategoryId(Long category);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetMealDishBysetMealId(Long id);
    @Select("select * from setmeal where id = #{setmealId}")
    Setmeal getsetmealBySetmealId(Long setmealId);
}
